#include "InfinitePlane.h"
#include "GeometricTools.h"


InfinitePlane::InfinitePlane(void)
{
}

InfinitePlane::~InfinitePlane(void)
{
}


bool InfinitePlane::Intersect(Line* line, IntersectInfo *pInfo)
{
    Line lineReflect;

    float fRayPos[] = {line->GetPos().x, line->GetPos().y, line->GetPos().z};
    float fRayDir[] = {line->GetDirection().x, line->GetDirection().y, line->GetDirection().z};
    float fNormal[] = {m_vNormal.x, m_vNormal.y, m_vNormal.z};
    float fPoint[]  = {m_vPoint.x, m_vPoint.y, m_vPoint.z};
    float fIntersect[3] = {0};

    if ( GeometricTools::LineIntersectPlane(fRayDir, fRayPos, fNormal, fPoint, fIntersect))
    {
        pInfo->fPoint = Vector3f(fIntersect[0], fIntersect[1], fIntersect[2]);

        // Set the distance
        pInfo->fDistance = Distance(line->GetPos(), pInfo->fPoint);

        // Set the normal, normal of sphere can be calculated directly.
        pInfo->vNormal = m_vNormal;

        // Set the material
        pInfo->pMaterial = GetMaterial();
        
        return true;
    }


    return false;
}
